package com.clkj.zhonghui.controller.stored;

import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.pojo.stored.ActivitySharingRecord;
import com.clkj.zhonghui.service.stored.ActivityLotteryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * @Author：周佳润
 * @Date：2024/7/18 上午9:15
 */
@RestController
@RequestMapping(value = "/lottery")
@Api(value = "/lottery", tags = {"抽奖"})
@CrossOrigin
public class ActivityLotteryController {

    @Autowired
    private ActivityLotteryService activityLotteryService;

    @ApiOperation(value = "用户添加分享活动用户申请记录")
    @PostMapping("/addActivityLottery")
    public Result addActivitySharingRecord(ActivitySharingRecord activitySharingRecord,
                                           HttpServletRequest request, @ApiParam("flag,add为添加，edit 修改") @RequestParam String flag){
        try {
            activityLotteryService.addActivityLottery(activitySharingRecord,request,flag);
            return new Result(true, StatusCode.OK,"操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"操作失败");
        }
    }

    @PostMapping("/getActivityLotteryList")
    @ApiOperation(value = "获取分享活动用户申请记录")
    public Result getActivitySharingRecordList(@ApiParam(name = "shopId", value = "门店ID 传0获取全部") @RequestParam("shopId") Integer shopId,
                                               @ApiParam(name = "recordFlag", value = "审核状态 0未审核 1审核通过 2驳回 -1查全部") @RequestParam("recordFlag") Integer recordFlag,
                                               Integer page, Integer size) {
        try {
            PageInfo pageInfo = activityLotteryService.getActivityLotteryList(shopId,recordFlag,page,size);
            return new Result(true, StatusCode.OK, "操作成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    @PostMapping("/authActivityLottery")
    @ApiOperation(value = "审核分享活动用户申请记录")
    public Result authActivitySharingRecord(ActivitySharingRecord activitySharingRecord) {
        try {
            activityLotteryService.authActivityLottery(activitySharingRecord);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    @PostMapping("/getActivityUserList")
    @ApiOperation(value = "某用户申请记录")
    public Result getActivityUserList(Integer userId) {
        try {
            List<ActivitySharingRecord> list = activityLotteryService.getActivityUserList(userId);
            return new Result(true, StatusCode.OK, "操作成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }


}
